package pl.ptemich.bumbastic;

public class Complex {

    private double real;
    
    private double img;

    public Complex(double real) {
        this.real = real;
        this.img = 0;
    }
    
    public Complex(double real, double img) {
        this.real = real;
        this.img = img;
    }
    
    public double getReal() {
        return real;
    }

    public double getImg() {
        return img;
    }
    
    public double abs() {
        return Math.sqrt((real * real) + (img * img)); 
    }
    
    public Complex add(Complex value) {
        return new Complex(real + value.getReal(), img + value.getImg()); 
    }
    
    public Complex sub(Complex value) {
        return new Complex(real - value.getReal(), img - value.getImg()); 
    }   
    
    public Complex mul(Complex value) {
        //(ac - bd) + (bc + ad)i
        return new Complex(real * value.getReal() - img * value.getImg(),
                           img * value.getReal() + real * value.getImg());
    }
    
    public double sin() {
        return img / this.abs();
    }
    
    public double cos() {
        return real / this.abs();
    }
    
    public Complex enhance(int index) {
        double angle = Math.acos(this.cos());
        double absEnh = this.abs();
        for (int e = 1; e < index; e++) {
            absEnh = absEnh * absEnh;
        }
        
        return new Complex(absEnh * Math.cos(index * angle),
                           absEnh * Math.sin(index * angle));
    }
    
    
    public Complex doubled() {
        return this.mul(this);
    }
}
